package com.nowcoder.面试必刷101;

import java.util.HashSet;

/**
 * @Description:
 * @author： yeswater
 * @create： 2024/6/13
 */

public class BM92 {
	public static void main(String[] args) {
		//int[] arr = {2,2,3,4,3};
		int[] arr = {1,2,3,4,1,5,6,7,8,1};
		System.out.println(maxLength(arr));
	}
	
	static public int maxLength (int[] arr) {
		if (arr == null || arr.length == 0) {
			return 0;
		}
		if (arr.length == 1) {
			return 1;
		}
		int max = 0;
		HashSet<Integer> set = new HashSet<>();
		for (int i = 0; i < arr.length - 1; i++) {
			set.add(arr[i]);
			for (int j = i + 1; j < arr.length; j++) {
				System.out.println("j=" + (j-1) + '\t' +set.toString());
				if (set.contains(arr[j])) {
					int size = set.size();
					max = Math.max(max, size);
					set.clear();
					break;
				}
				set.add(arr[j]);
			}
		}
		return Math.max(max, set.size());
	}
}
